<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" session="false" deferredSyntaxAllowedAsLiteral="true"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加场次</title>
<link href="${pageContext.request.contextPath}/page/admin/static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/page/admin/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
<script src="${pageContext.request.contextPath}/page/admin/lib/jquery/1.9.1/jquery.min.js"></script> 
<script src="${pageContext.request.contextPath}/static/lib/layer/2.4/layer.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/jquery.sPage.css">
<script src="${pageContext.request.contextPath}/static/js/jquery.sPage.js"></script>
</head>
<body>
<div class="page-container">
	<div class="mt-20">
		<form class="form form-horizontal" id="form-admin-add">
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>考试类型：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<select id="typeSelect">
				<option value="0">请选择考试类型</option>
				<c:forEach items="${typeList}" var="type" varStatus="status">
					<option value="${status.count}">${type.typeName}</option>
				</c:forEach>
			</select>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>科目：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<select id="subjectSelect">
			<option value="0">请选择科目</option>
			<option value="1">科目一</option>
			<option value="2">科目二</option>
			<option value="3">科目三 道路驾驶技能考试</option>
			<option value="3">科目三 安全文明驾驶常识考试</option>
		</select>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>考试时间：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="hidden" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}'})" id="logmin" class="input-text Wdate" style="width:120px;" autocomplete="off">
			<input type="text" onfocus="WdatePicker({ minDate:'%y-%M-#{%d+1}',maxDate:'2050-12-31'})" id="logmax" class="input-text Wdate" style="width:120px;" autocomplete="off">
			
		</div>
	</div>
	
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>考试人数：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input width="60%" type="text" value="" placeholder="" id="remain" name="phone" required="required" autocomplete="off"/> 人
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>场地：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input width="60%" type="text" value="" placeholder="" id="place" name="phone" required="required" autocomplete="off"/> 
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">时间段：</label>
		<div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
			<select class="select" name="adminRole" size="1" id="timesSelect">
				<option>08:00-11:00</option>
				<option>14:00-17:00</option>
			</select>
			</span> </div>
	</div>
	
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input id="submit" onclick=addSession() class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
		</div>
	</div>
	</form>
	
	</div>
	
</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript">
$(function(){
	
});
function addSession(){ //添加场次
	var typeName;
	var subject;
	var place = $("#place").val();
	var dates = $("#logmax").val(); 
	var remain = $("#remain").val(); //剩余人数
	var times = $("#timesSelect option:selected").text(); 
	if(0==$("#typeSelect").val()){
		typeName = '';
	} else {
		typeName = $("#typeSelect option:selected").text(); 
	}
	if(0==$("#subjectSelect").val()){
		subject = '';
	} else {
		subject = $("#subjectSelect option:selected").text(); 
	}
	if (validate()){
		$.ajax({
			url:"${pageContext.request.contextPath}/SessionManage/addSession",
			type:"get",
			data:{"typeName":typeName,"subject":subject,"dates":dates,"times":times,"remain":remain,"place":place},
			dataType:"json",
			async:false,
			success:function(data){
				if(1==data.res){ //成功
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index); //再执行关闭
					location.reload();
					layer.msg('添加成功',{icon:1,time:2000});
				}
				if(0==data.res){ //失败（已存在）
					layer.msg('该场次已存在',{icon:0,time:2000});
				}
			},
			error:function(){
				alert('error');
			}
		});
	}
}
function validate(){ //验证输入的合法性
	var res = true;
	var typeName;
	var subject;
	var place = $("#place").val();
	var dates = $("#logmax").val(); 
	var remain = $("#remain").val(); //剩余人数
	var times = $("#timesSelect option:selected").text(); 
	if(0==$("#typeSelect").val()){
		typeName = '';
	} else {
		typeName = $("#typeSelect option:selected").text(); 
	}
	if(0==$("#subjectSelect").val()){
		subject = '';
	} else {
		subject = $("#subjectSelect option:selected").text(); 
	}
	if(''==times){
		layer.msg('请选择时间段',{icon:0,time:2000});
		res = false;
	}
	if(''==place){
		layer.msg('请输入场地',{icon:0,time:2000});
		res = false;
	} 
	if(''==remain){
		layer.msg('请输入考试人数',{icon:0,time:2000});
		res = false;
	}
	if(''==dates){
		layer.msg('请选择考试时间',{icon:0,time:2000});
		res = false;
	}
	if(''==subject){
		layer.msg('请选择科目',{icon:0,time:2000});
		res = false;
	}
	if(''==typeName){
		layer.msg('请选择考试类型',{icon:0,time:2000});
		res = false;
	}
	return res;
}
</script> 
</body>
</html>